<?php
session_start();
require_once( 'master_db.php' );
 
$type = new M_master();
$user_id = $_SESSION['userid'];

if (isset($_POST['m'])  &&  $_POST['m']!=""){

    if ($_POST['m']== 'load'){
      $result=$type->loadSupplier();
      $rows=$type->getRowCount();
      $i=1;
      $html="";
      if ($rows>0){
           $data = array();
            while($row = $result->FetchRow()){
               $data[] = array(0,$row['id'],$row['name'],$row['address'],$row['telephone'], $row['status']) ;
            }
        }else{
			$data = array();
        }
    
        $arr = array('aaData'=>$data);
        
        echo json_encode($arr);
      
    }else if ($_POST['m']=='add'){
        $ar = array();
		$ar['name']=  $_POST['name'];
		$ar['address']=  $_POST['address'];
		$ar['telephone']=  $_POST['tele'];
		$ar['status'] = $_POST['s'];
		$ar['createdate'] =date( "Y/m/d H:i:s" );
		$ar['createby'] = $user_id;
		$id=$type->insertDataWithSql("SELECT name, address, telephone, status, createdate, createby From tb_supplier WHERE 1=2 ",$ar);
		
    }else if ($_POST['m']=='edit'){
		$ar = array();
		$ar['name']=  $_POST['name'];
		$ar['address']=  $_POST['address'];
		$ar['telephone']=  $_POST['tele'];
		$ar['status'] = $_POST['s'];
		$ar['updatedate'] =date( "Y/m/d H:i:s" );
		$ar['updateby'] = $user_id;
		$strcipt = $type->updateDataWithSql(" SELECT name, address, telephone, status, createdate, createby From tb_supplier WHERE id=".$_POST['id'],$ar);
		// echo json_encode($strcipt);
	}
	else if ($_POST['m']=='del'){
         $id=$_POST['id'];
		 $type->setTable($_POST['tb']);  
		 $type->deleData($id);
		 
    } 
 
}else{
}
 
?>